/**
 * 认证相关API
 * 包括登录、注册、退出登录等功能
 */
import request from '@/utils/request.js'

/**
 * 用户登录
 * @param {String} username 用户名/账号
 * @param {String} password 密码
 * @returns {Promise}
 */
export const login = (username, password) => {
	return request.post('/douyang/auth/login/usernamePassword', {
		username,
		password
	}, {
		loadingText: '登录中...'
	})
}

/**
 * 用户注册
 * @param {String} username 用户名/账号
 * @param {String} password 密码
 * @returns {Promise}
 */
export const register = (username, password) => {
	return request.post('/douyang/auth/register/usernamePassword', {
		username,
		password
	}, {
		loadingText: '注册中...'
	})
}

/**
 * 退出登录
 * @returns {Promise}
 */
export const logout = () => {
	return request.post('/auth/logout', {}, {
		loading: false
	})
}

/**
 * 获取用户信息
 * @returns {Promise}
 */
export const getUserInfo = () => {
	return request.get('/auth/userinfo', {}, {
		loading: false
	})
}

/**
 * 刷新token
 * @returns {Promise}
 */
export const refreshToken = () => {
	return request.post('/auth/refresh', {}, {
		loading: false,
		showError: false
	})
}
